package com.example.lenovo.a203_yhy_ordering_3.model;

import com.example.lenovo.a203_yhy_ordering_3.beans.FoodInfoBean;
import com.example.lenovo.a203_yhy_ordering_3.beans.IsCollectBean;
import com.example.lenovo.a203_yhy_ordering_3.iface.IsCollectIface;
import com.example.lenovo.a203_yhy_ordering_3.listener.IsCollectListener;
import com.example.lenovo.a203_yhy_ordering_3.service.FoodInfoService;
import com.example.lenovo.a203_yhy_ordering_3.service.IsCollectService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2018/12/3.
 */

public class IsCollectModel implements IsCollectIface{
    private Retrofit retrofit;


    public IsCollectModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getIsCollectResult(int user_id, int shop_food_id, int flag, final IsCollectListener isCollectListener) {
        IsCollectService isCollectService = retrofit.create(IsCollectService.class);

        Call<IsCollectBean> isCollectCall = isCollectService.isCollected(user_id, shop_food_id, flag);

        isCollectCall.enqueue(new Callback<IsCollectBean>() {
            @Override
            public void onResponse(Call<IsCollectBean> call, Response<IsCollectBean> response) {
                if(response!=null)
                    isCollectListener.onResponse(response.body());
                else
                    isCollectListener.onFail("判断收藏失败");
            }

            @Override
            public void onFailure(Call<IsCollectBean> call, Throwable t) {
                isCollectListener.onFail(t.toString());
            }
        });
    }
}
